package com.suixun.controller;

import java.math.BigDecimal;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.authority.controller.BaseManager;
import com.suixun.service.DevicePriceService;
import com.suixun.vo.SchoolDiscountVO;
import com.suixun.vo.SystemPriceVO;

/**
 * <p>
 * Title: DevicePriceManage
 * </p>
 * <p>
 * 功能描述: 价格管理
 * </p>
 * 
 * @author 陈显强
 * @date 2017年11月4日上午10:37:53
 * @version 1.0
 */
@Controller
@RequestMapping(value = "/devicePriceManage")
public class DevicePriceManage extends BaseManager {
	@Resource
	private DevicePriceService devicePriceService;

	@RequestMapping("getSystemPrice")
	@ResponseBody
	public Object getSystemPrice() {
		return success(devicePriceService.getSystemPrice());
	}

	@RequestMapping("saveSystemPrice")
	@ResponseBody
	public Object saveSystemPrice(BigDecimal smartCardPrice, BigDecimal whiteCard13_56Price,
			BigDecimal whiteCard2_4Price, BigDecimal packagePrice) {
		SystemPriceVO systemPrice = new SystemPriceVO();
		systemPrice.setPackagePrice(packagePrice);
		systemPrice.setSmartCardPrice(smartCardPrice);
		systemPrice.setWhiteCard13_56Price(whiteCard13_56Price);
		systemPrice.setWhiteCard2_4Price(whiteCard2_4Price);
		String result = devicePriceService.updateSystemPrice(systemPrice);
		if (result == null) {
			return success();
		} else {
			return fail(result);
		}
	}

	@RequestMapping("getSchoolPrices")
	@ResponseBody
	public Object getSchoolPrices(String schoolName) {
		if (StringUtils.isBlank(schoolName)) {
			return fail("学校名称为空");
		}
		return success(devicePriceService.getSchoolPrices(schoolName));
	}

	@RequestMapping("saveSchoolPrice")
	@ResponseBody
	public Object saveSchoolPrice(BigDecimal packagePrice, BigDecimal smartCardPrice, BigDecimal whiteCard13_56Price,
			BigDecimal whiteCard2_4Price, String schoolName) {
		SchoolDiscountVO schoolPrice = new SchoolDiscountVO();
		schoolPrice.setPackagePrice(packagePrice);
		schoolPrice.setSchoolName(schoolName);
		schoolPrice.setSmartCardPrice(smartCardPrice);
		schoolPrice.setWhiteCard13_56Price(whiteCard13_56Price);
		schoolPrice.setWhiteCard2_4Price(whiteCard2_4Price);
		String result = devicePriceService.addSchoolPrices(schoolPrice);
		if (result == null) {
			return success();
		} else {
			return fail(result);
		}
	}

	@RequestMapping("updateSchoolPrice")
	@ResponseBody
	public Object updateSchoolPrice(BigDecimal packagePrice, BigDecimal smartCardPrice, BigDecimal whiteCard13_56Price,
			BigDecimal whiteCard2_4Price, String schoolName) {
		SchoolDiscountVO schoolPrice = new SchoolDiscountVO();
		schoolPrice.setPackagePrice(packagePrice);
		schoolPrice.setSchoolName(schoolName);
		schoolPrice.setSmartCardPrice(smartCardPrice);
		schoolPrice.setWhiteCard13_56Price(whiteCard13_56Price);
		schoolPrice.setWhiteCard2_4Price(whiteCard2_4Price);
		String result = devicePriceService.updateSchoolPrices(schoolPrice);
		if (result == null) {
			return success();
		} else {
			return fail(result);
		}
	}

	@RequestMapping("deleteSchoolPrices")
	@ResponseBody
	public Object deleteSchoolPrices(String schoolName, Integer deviceType) {
		SchoolDiscountVO schoolPrice = new SchoolDiscountVO();
		schoolPrice.setSchoolName(schoolName);
		schoolPrice.setDevicetype(deviceType);
		String result = devicePriceService.deleteSchoolPrices(schoolPrice);
		if (result == null) {
			return success();
		} else {
			return fail(result);
		}
	}

	@RequestMapping("getDevicePrice")
	@ResponseBody
	public Object getDevicePrice(String mdtid) {
		Object result = devicePriceService.getDevicePrice(mdtid);
		if (result != null && result instanceof String) {
			return fail(result.toString());
		} else {
			return success(result);
		}
	}

	@RequestMapping("saveDevicePackagePrice")
	@ResponseBody
	public Object saveDevicePackagePrice(String mdtid, BigDecimal packagePrice) {
		String result = devicePriceService.saveDevicePackagePrice(mdtid, packagePrice);
		if (result != null) {
			return fail(result);
		} else {
			return success();
		}
	}

	@RequestMapping("deleteDevicePackagePrice")
	@ResponseBody
	public Object deleteDevicePackagePrice(String mdtid) {
		String result = devicePriceService.deleteDevicePackagePrice(mdtid);
		if (result != null) {
			return fail(result);
		} else {
			return success();
		}
	}
}
